package com.wuyi.tea.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuyi.tea.domain.dto.OrderDTO;
import com.wuyi.tea.domain.pojo.Order;
import com.wuyi.tea.domain.vo.OrderDetailVO;
import com.wuyi.tea.domain.vo.OrderVO;
import com.wuyi.tea.domain.vo.R;
import com.wuyi.tea.service.OrderService;
import com.wuyi.tea.util.LocalStorageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Api(tags = "订单模块")
@RestController(value = "UserOrderController")
@RequestMapping("/user/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    @ApiOperation("查看所有订单")
    @GetMapping("/list")
    public R list(){
        log.info("id为{}的用户查看所有的订单",LocalStorageUtil.get());
        List<OrderDetailVO> list= orderService.getAllList();
        return R.success(list);
    }

    @ApiOperation("查看待付款订单")
    @GetMapping("/needPay")
    public R needPay(){

        log.info("id为{}的用户查看了所有待支付的订单", LocalStorageUtil.get());
        List<OrderDetailVO> orderVOS=orderService.listNeedPay();

        return R.success(orderVOS);
    }

    @ApiOperation("查看已付款订单")
    @GetMapping("/alreadyPay")
    public R alreadyPay(){
        log.info("id为{}的用户查看了所有已支付的订单",LocalStorageUtil.get());
        List<OrderDetailVO> orderVOS=orderService.listAlReadyPay();
        return R.success(orderVOS);
    }


    @ApiOperation("查看单个订单")
    @GetMapping("/detail")
    public R getOrderDetail(@RequestParam Long orderId){
        log.info("id为{}的用户查看了单个订单,订单id:{}",LocalStorageUtil.get(), orderId);
        OrderDetailVO orderDetail = orderService.getOrderDetail(orderId);
        return R.success(orderDetail);
    }

    @ApiOperation("添加订单")
    @PostMapping("/detail")
    public R addOrder(@RequestBody OrderDTO orderDTO){

        log.info("id为{}的用户添加了订单：\n{}",LocalStorageUtil.get(),orderDTO);
        orderService.addOrder(orderDTO);
        return R.success(orderDTO.getId());
    }


    @ApiOperation("删除订单")
    @DeleteMapping("/detail")
    public R deleteOrder(@RequestParam Long orderId){

        log.info("id为{}的用户正在删除订单: {}", LocalStorageUtil.get(),orderId);
        orderService.deleteOrder(orderId);
        return R.success();
    }



}
